#ifndef CHAPTER15_RTTI1_H_
#define CHAPTER15_RTTI1_H_

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
class Grand
{
private:
	int hold;
public:
	Grand(int h=0):hold(h) { }
	virtual void Speak() const { cout << "I am a grand class!\n"; }
	virtual int Value() const { return hold; }
};

class Superb :public Grand
{
public:
	Superb(int h=0):Grand(h) { }
	void Speak() const { cout << "I am a superb class!\n"; }
	virtual void Say() const
	{
		cout << "I hold the superb value of " << Value() << "!\n";
	}
};

class Magnificent :public Superb
{
private:
	char ch;
public:
	Magnificent(int h = 0, char c = 'A'):Superb(h),ch(c) { }
	void Speak() const { cout << "I am a magnificent class!!!\n"; }
	void Say() const {
		cout << "I hold the charactoer " << ch <<
			"and the integer " << Value() << "!\n";
	}
};

Grand * GetOne()		//generate one of three kinds of objects randomly
{
	Grand * p;
	switch (rand() % 3)
	{
	case 0:p = new Grand(rand() % 100);
		break;
	case 1:p = new Superb(rand() % 100);
		break;
	case 2:p = new Magnificent(rand() % 100, 'A' + rand() % 26);
		break;
	}
	return p;
}
#endif
